package demo2;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-09-16
 * Time: 22:29
 */
public class Test3 {
    public static Object locker1 = new Object();
    public static Object locker2 = new Object();
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (locker1){
                try {
                    locker1.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName());
            }
        }, "线程a");
        Thread t2 = new Thread(() -> {
            synchronized (locker2){
                try {
                    locker2.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName());
                synchronized (locker1){
                    locker1.notify();
                }
            }
        }, "线程b");
        Thread t3 = new Thread(() -> {
            synchronized (locker2){
                System.out.println(Thread.currentThread().getName());
                locker2.notify();
            }
        }, "线程c");
        t1.start();
        t2.start();
        t3.start();

    }
}
